package se.rkrantz.simpleraid.hibernate.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;


@Entity
@Table(name = "RAID")
public class Raid {
	private long raidId;
	private DateTime raidDate;
	private String raidTitle;

	private Set<Signup> signups;

	@Id
	@GeneratedValue
	@Column(name = "RAID_ID")
	public long getRaidId() {
		return raidId;
	}

	public void setRaidId(long raidId) {
		this.raidId = raidId;
	}

	@Column(name = "RAID_DATE", nullable = false)
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getRaidDate() {
		return raidDate;
	}

	public void setRaidDate(DateTime raidDate) {
		this.raidDate = raidDate;
	}

	@Column(name = "RAID_TITLE", nullable = false)
	public String getRaidTitle() {
		return raidTitle;
	}

	public void setRaidTitle(String raidTitle) {
		this.raidTitle = raidTitle;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "RAID_SIGNUP", joinColumns = { @JoinColumn(name = "RAID_ID")}, inverseJoinColumns = { @JoinColumn(name = "SIGNUP_ID")})
	public Set<Signup> getSignups() {
		return signups;
	}

	public void setSignups(Set<Signup> signups) {
		this.signups = signups;
	}
	
	public void addSignup(Signup signup) {
		signups.add(signup);
	}

}
